package com.hanggold.jfinal.excel.demo;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-06-07 16:03
 * @since 1.0.0
 **/
public class FreemarkerDemo {
    
    public static void main(String[] args) throws IOException, TemplateException {
        Map<String, Object> map = new HashMap<>(2);
        
        map.put("number","222");
        String temp = "/Users/smc/data/test-data/easy-excel/students22.xml";
        
        Configuration configuration = new Configuration(Configuration.VERSION_2_3_31);
        
        configuration.setDefaultEncoding("UTF-8");
        
        configuration.setDirectoryForTemplateLoading(new File("/Users/smc/data/test-data/easy-excel/template"));
        
//        configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
//        configuration.setLogTemplateExceptions(false);
//        configuration.setWrapUncheckedExceptions(true);
//        configuration.setFallbackOnNullLoopVariable(false);
        
        Template template = configuration.getTemplate("students22.ftl");
        
        File file = new File("/Users/smc/data/test-data/easy-excel/studentsssss.xls");
        FileWriter fileWriter = new FileWriter(file);
        template.process(map, fileWriter);
        
        fileWriter.flush();
        fileWriter.close();
        System.out.println("success");
    }
}
